<script setup>
import { ref } from 'vue';

const isShow = ref(false)

const openModal = isOpen =>  isShow.value = isOpen
</script>

<template>
    <h2>Teleport</h2>
    <Teleport to="body">
        <section v-if="isShow" class="modal">
            <div class="inner">
                <main>我是弹窗</main>
                <footer><button @click="openModal(false)">关闭弹窗</button></footer>
            </div>
        </section>
    </Teleport>
    <button @click="openModal(true)">打开弹窗</button>
</template>
<style scoped>
.modal{
    background-color: rgba(0,0,0,.5);
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.inner{
    width: 500px;
    height: 300px;
    background-color: #fff;
    border-radius: 10px;
}

.inner main {
    font-size: 30px;
    height: 80% ;
    padding-top: 20px;
    text-align: center;
}

.inner footer{
    margin-right: 10px;
    float: right;
}
</style>

